package com.zj.leetcode.medium.greed;

import java.util.Arrays;

/**
 * @program: algorithm
 * @description:
 * 摆动排序 II
 * 324 wiggle-sort-ii
 * @author: Zhang Bo
 * @create: 2022-04-01 19:18:19
 **/
public class WiggleSortIi{
    public static void main(String[] args) {
        Solution solution = new WiggleSortIi().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        /**
         *
         * @param nums
         */
        public void wiggleSort(int[] nums) {

            Arrays.sort(nums);

            int n = nums.length;
            int p = n - 1;
            int[] tmp = new int[n];
            for (int i = 1; i < n; i += 2) {
                tmp[i] = nums[p--];
            }
            for (int i = 0; i < n; i += 2) {
                tmp[i] = nums[p--];
            }
            System.arraycopy(tmp, 0, nums, 0, n);

        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
